<?php
/*
Template Name: Tours
*/

get_header();

$layout='right';
$view='list';
$page_limit=12;
$row_limit=$layout!='left' && $layout!='right' ? 4 : 3;
$row_class=$row_limit==4 ? 'three' : 'four';
$booking=get_option('themex_tours_booking');
$questions=get_option('themex_tours_questions');
$date_format=ThemexCore::getOption('date_format','m/d/Y');
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
//$bbtours = bb_tours_query();

$args=array(
	'post_type'=> array('post','tour','evento','offerta'),
	'posts_per_page'=>intval($page_limit),
	'paged'=>$paged,
	's'=> $_GET['s'],
);

$query=new WP_Query(array('post__in'=>array($post->ID)));
query_posts($args);

if($layout=='left') {
?>
<div class="column threecol">
<?php get_sidebar(); ?>
</div>
<div class="column ninecol last">
<?php } else if($layout=='right') { ?>
<div class="column ninecol">
<?php } else { ?>
<div class="fullwidth-block">
<?php } ?>
	<div class="<?php echo $view=='list' ? 'items-list' : 'items-grid'; ?>">
		<?php 
		$counter=0;
		if (have_posts()) {
			while ( have_posts() ) {
				the_post();	
				$destinations=themex_category($post->ID, 'destination');
				$duration=themex_duration($post->ID);
				$departure_date=themex_date(get_post_meta($post->ID, '_tour_departure_date', true), $date_format);
				$arrival_date=themex_date(get_post_meta($post->ID, '_tour_arrival_date', true), $date_format);
				$days=themex_days(get_post_meta($post->ID, '_tour_days', true));
				$price=themex_price($post->ID);
				
				if($view=='list') {
				?>
				<div class="full-tour">
					<div class="fivecol column">
						<div class="fade-slider-container tour-slider-container">
							<div class="featured-image">
								<a href="<?php the_permalink(); ?>"><img src="<?php echo themex_thumbnail($post->ID, 460); ?>" alt="<?php the_title(); ?>" /></a>
							</div>
							<div class="block-background layer-2"></div>
						</div>
					</div>
					<div class="sevencol column last">
						<div class="block-title">
							<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
						</div>
						<?php if($duration!='' || $price!='' || $destinations!='' || $departure_date!='') { ?>
						<ul class="tour-meta">
							<?php if($destinations!='') { ?><li><div class="colored-icon icon-2"></div><strong><?php _e('Destination','midway'); ?>:</strong> <?php echo $destinations; ?></li><?php } ?>
							<?php if($duration!='') { ?><li><div class="colored-icon icon-1"><span></span></div><strong><?php _e('Duration','midway'); ?>:</strong> <?php echo $duration; ?></li><?php } ?>		
							<?php if($departure_date!='' && $days=='') { ?><li><div class="colored-icon icon-6"><span></span></div><strong><?php _e('Departs','midway'); ?>:</strong> <?php echo $departure_date; ?></li><?php } ?>
							<?php if($arrival_date!='' && $days=='') { ?><li><div class="colored-icon icon-7"><span></span></div><strong><?php _e('Arrives','midway'); ?>:</strong> <?php echo $arrival_date; ?></li><?php } ?>
							<?php if($days!='') { ?><li><div class="colored-icon icon-6"><span></span></div><strong><?php _e('Runs On','midway'); ?>:</strong> <?php echo $days; ?></li><?php } ?>
							<?php if($price!='') { ?><li><div class="colored-icon icon-3"><span></span></div><strong><?php _e('Price','midway'); ?>:</strong> <?php echo $price; ?></li><?php } ?>
						</ul>
						<?php } ?>
						<p><?php echo themex_excerpt(get_the_excerpt()); ?></p>
						<?php if($booking!='true') { ?><a href="#booking-form" data-id="<?php echo $post->ID; ?>" data-title="<?php the_title(); ?>" class="button small fancybox tour-button"><span><?php _e('Book Now','midway'); ?></span></a><?php } ?>
						<?php if($questions!='true') { ?><a href="#question-form" data-id="<?php echo $post->ID; ?>" data-title="<?php the_title(); ?>" class="button grey small fancybox tour-button"><span><?php _e('Ask a Question','midway'); ?></span></a><?php } ?>
					</div>
					<div class="clear"></div>
				</div>
				<?php
				} else {
					$counter++;		
					?>
					<div class="column <?php echo $row_class; ?>col <?php echo $counter==$row_limit ? 'last' : ''; ?>">
						<div class="tour-thumb-container">
							<div class="tour-thumb">						
								<a href="<?php the_permalink(); ?>"><img src="<?php echo themex_thumbnail($post->ID, 460); ?>" class="fullwidth" alt="<?php the_title(); ?>" /></a>
								<div class="tour-caption">
									<h5 class="tour-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
									<?php if($destinations!='' || get_post_meta($post->ID,'_tour_duration',true)!='') { ?>
									<div class="tour-meta">
										<?php if($destinations!='') { ?>
										<div class="tour-destination"><div class="colored-icon icon-2"></div><?php echo $destinations; ?></div>
										<?php } ?>
										<?php if($duration!='') { ?>
										<div class="tour-duration"><?php echo $duration; ?></div>
										<?php } ?>
									</div>
									<?php } ?>
								</div>								
							</div>		
							<div class="block-background"></div>
						</div>
					</div>
					<?php 
					if($counter==$row_limit) {
						$counter=0;
						echo '<div class="clear"></div>';
					}
				}
			}
		} else {
		?>
		<h3><?php _e('No tours found. Try a different search?','midway'); ?></h3>
		<p><?php _e('Sorry, no tours matched your search.','midway'); ?> <?php _e('View','midway'); ?> <a href="<?php echo home_url(); ?>/?s="><?php _e('all tours','midway'); ?></a> <?php _e('or try adjusting the search parameters','midway'); ?>.</p><br />
		<?php }	?>
		<?php if($view=='grid') { ?>
		<div class="clear"></div>
		<?php }	?>
	</div><!-- items list -->	
	<?php 
	themex_pagination(); 
	wp_reset_query(); 
	?>
	<?php get_template_part('module','forms'); ?>
</div>
<?php if($layout=='right') { ?>
<div class="column threecol last">
<?php get_sidebar(); ?>
</div>
<?php } ?>
<?php get_footer(); ?>